if (!cms24k) {
	var cms24k = {}
};
$.extend(true, cms24k, {
	getSortCol : function(dataGridDatas) {
		return this.getGridDataValue(dataGridDatas, 'iSortCol_0');
	},
	getSortDirect : function(dataGridDatas) {
		return this.getGridDataValue(dataGridDatas, 'sSortDir_0');
	},
	getGridDataValue : function(dataGridDatas, key) {
		var result;
		$(dataGridDatas).each(function(index, value) {
			if (value) {
				if (value.name == key) {
					result = value.value;
					return false
				} else {
					return true;
				}
			}

		});
		return result;
	},
	getRules : function(){
		var rules = "";
		$(".filterdata").each(
				function(index, value) {
 					if ($(this).attr("type") ==='checkbox'){
						if ($( this ).is(":checked")){
							rules +=cms24k.getRuleByInput(this);
						}
						
					}
					else{
					if ($(this).val()) {
						rules += cms24k.getRuleByInput(this);
					}
					}
				});
		rules = rules.substring(0, rules.length - 1)
		return rules;
	},
	
	getRuleByInput : function(obj){
		var op = $(obj).attr("op");
		var field = $(obj).attr("field");
		var data = $(obj).val();
		return '{"field":"' + field + '","op":"' + op
				+ '","data":"' + data + '"},';

	},
	
	initQueryData : function(aoData, columnHeader) {
		var sortColn = this.getSortCol(aoData);
		var sortOrder = this.getSortDirect(aoData);
		var sortOrderBy = columnHeader[sortColn];
		var iDisplayStart = aoData[3].value;
		var iDisplayLength = aoData[4].value;
		var pageNo = parseInt(iDisplayStart / iDisplayLength, 10) + 1;
		var rules = this.getRules();
		return {
			"pageNo" : pageNo,
			"pageSize" : iDisplayLength,
			"order" : sortOrder,
			"orderBy" : sortOrderBy,
			"filters" : '{"groupOp":"AND","rules":[' + rules + ']}'
		};

	},
});

$.extend(
				$.fn.dataTable.defaults,
				{
					"sPaginationType" : "full_numbers",
					"bJQueryUI" : false,
					"bAutoWidth" : false,
					"bLengthChange" : false,
					"bFilter" : false,
					"aaSorting" : [ [ 0, "asc" ] ],
					"bProcessing" : true,
					"bServerSide" : true,
					"fnServerData" : function(sUrl, aoData, fnCallback,
							oSettings) {
						var echo = aoData[0].value;
						var data = new QueryData(aoData);
						var filter = data["filters"];
						delete data['filters'];
 						oSettings.jqXHR = $
								.ajax( {
									"url" : sUrl+"/"+filter+"/",
									"data" : data,
									"success" : function(json) {
										json = new DataTableForm(json, echo);
										if (json.sError) {
											oSettings.oApi._fnLog(oSettings, 0,
													json.sError);
										}
 										$(oSettings.oInstance).trigger('xhr',
												[ oSettings, json ]);
										fnCallback(json);	
										
										if (typeof successExtend == 'function') { 
											successExtend(); 
										}
									},
									"dataType" : "json",
									"cache" : false,
									"type" : oSettings.sServerMethod,
									"error" : function(xhr, error, thrown) {
										if (error == "parsererror") {
											oSettings.oApi
													._fnLog(
															oSettings,
															0,
															"DataTables warning: JSON data from "
																	+ "server could not be parsed. This is caused by a JSON formatting error.");
										}
									}
								});
					}
				});